import {
  LOGIN,MODIFYUSERINFO,MODIFYSERVICER,getServiceinfo,TENANTPUSH,STOREPUSH,TENANTBIND,STOREBIND
} from '../actions'
import hhistory from '../history'
import { Toast } from 'antd-mobile'

export default store => next => action => {
	if( action.type === LOGIN && action.data.code === "0"){
		hhistory.push( '/main' )
		return next(action)
	}else if( action.data && ( action.data.code === "-10086" 
							|| action.data.code === "-10006" ) ){
		hhistory.push( '/' )
	}else if( action.data && (action.data.code === "-10014"
						   || action.data.code === "-10005" ) ){
		Toast.info( action.data.msg,3 )
	}else if( action.data && action.data.code === "-10001" ){
		Toast.success(action.data.msg,1)
	}else if( action.type === MODIFYUSERINFO ){
		Toast.success('修改成功', 1);
		return next(action)
	}else if( action.type === MODIFYSERVICER ){
		store.dispatch( getServiceinfo(action.params.urlparam) )
	}else if(action.type === TENANTPUSH || action.type === STOREPUSH||action.type === TENANTBIND||action.type === STOREBIND){
        if(action.data.code === "0"){
            Toast.success(action.data.msg, 1,() => {
                hhistory.push( '/main' );
			});
		}else{
            Toast.fail(action.data.msg, 1.5);
		}
	}else{
		Toast.hide()
		return next(action)
	}
}